//
//  AppDependences.m
//  ViperDemo
//
//  Created by Leeesven on 17/5/12.
//  Copyright © 2017年 Leeesven. All rights reserved.
//

#import "AppDependences.h"

#import "DeviceClock.h"

#import "RootWireframe.h"
#import "ListWireframe.h"
#import "ListPresenter.h"
#import "ListInteractor.h"
#import "ListDataManager.h"

#import "CoreDataStore.h"

@interface AppDependences()

@property (nonatomic, strong) ListWireframe *listWireframe;

@end

@implementation AppDependences

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self configureDependencies];
    }
    return self;
}

-(void)installRootViewControllerIntoWindow:(id)window{
    [self.listWireframe presentListInterfaceFromWindow:window];
}

-(void)configureDependencies{
    NSLog(@"AppDependences configureDependencies start");
    
    DeviceClock *clock = [DeviceClock new];
    RootWireframe *rootWireframe = [RootWireframe new];
    
    CoreDataStore *dataStore = [CoreDataStore new];
    
    // List Modules
    ListWireframe *listWireframe = [ListWireframe new];
    ListPresenter *listPresenter = [ListPresenter new];
    ListDataManager *listDataManager = [[ListDataManager alloc] init];
    ListInteractor *listInteractor = [[ListInteractor alloc] initWithDataManager:listDataManager clock:clock];
    
    // Add Modules
    
    listDataManager.dataStore = dataStore;
    
    listInteractor.output = listPresenter;
    
    listPresenter.listInteractor = listInteractor;
    listPresenter.listWireframe = listWireframe;
    
    listWireframe.rootWireframe = rootWireframe;
    listWireframe.listPresenter = listPresenter;
    self.listWireframe = listWireframe;
    
    NSLog(@"AppDependences configureDependencies end");
}

@end
